#e
#Title[zNuXgtgR̉΁v]
#Text[Fl̗Ⓚe炦I]
#ScriptVersion[2]

script_enemy_main
{
	let alpha=255;
	let scroll=0;
	let flag=0;
	let cx=GetCenterX();
	let cy=GetCenterY();
	let boss=GetCurrentScriptDirectory~"img\boss7-2.png";
	let eye=GetCurrentScriptDirectory~"img\bg7-1.png";
	let asa=GetCurrentScriptDirectory~"img\bg7-2.png";
	let moya=GetCurrentScriptDirectory~"img\bg7-3.png";
	LoadUserShotData(GetCurrentScriptDirectory~"shot.txt");
	@Initialize
	{
		SetScore(30000);
		SetLife(510);
		SetDamageRate(10,0);
		SetMovePosition02(cx,cy,60);
		SetTimer(80);
		SetInvincibility(60);
		LoadGraphic(boss);
		LoadGraphic(eye);
		LoadGraphic(asa);
		LoadGraphic(moya);
		LoadGraphic(GetCurrentScriptDirectory~"img\enemy\magic.png");
		shottask;
		subtask;
		drawtask;
		CutIn(YOUMU,"zNuXgtgR̉΁v",0,0,0,0,0);
	}
	@MainLoop
	{
		yield;
	}
	@Finalize
	{
		loop(16)
		{
			CreateItem(ITEM_SCORE,GetX+rand(-30,30),GetY+rand(-30,30));
		}
		DeleteGraphic(boss);
		DeleteGraphic(eye);
		DeleteGraphic(asa);
		DeleteGraphic(moya);
		DeleteGraphic(GetCurrentScriptDirectory~"img\enemy\magic.png");
	}
	@DrawLoop
	{
		SetTexture(boss);	
		if(flag==1)
		{
			SetGraphicRect(52,0,81,63);
		}
		else if(flag==2)
		{
			SetGraphicRect(24,0,52,63);
		}
		else
		{
			SetGraphicRect(0,0,24,63);
		}
		SetGraphicScale(1,1);
		SetGraphicAngle(0,0,0);
		SetAlpha(alpha);
		DrawGraphic(GetX,GetY);
	}
	@BackGround
	{
		SetColor(128,128,128);
		SetTexture(eye);	
		SetGraphicRect(0,0,384,448);
		SetAlpha(255);
		SetGraphicScale(1,1);
		SetGraphicAngle(0,0,0);
		DrawGraphic(cx,cy);
		SetColor(255,255,255);
		SetTexture(asa);	
		SetGraphicRect(0,0,888,189*5);
		SetAlpha(64);
		SetGraphicScale(0.5,0.75);
		SetGraphicAngle(0,0,0);
		DrawGraphic(cx+scroll,cy);
		DrawGraphic(cx+scroll-444,cy);
		if(scroll>444)
		{
			scroll=0;
		}
	}
	task shottask
	{
		wait(120);
		CreateEnemyFromScript("migo2",cx,cy-120,0,0,0);
		wait(40);
		CreateEnemyFromScript("migo",cx+180,cy-30,0,0,0);
		wait(40);
		CreateEnemyFromScript("migo",cx-180,cy-30,0,0,0);
		wait(40);
		CreateEnemyFromScript("migo",cx+60,cy-60,0,0,0);
		wait(40);
		CreateEnemyFromScript("migo2",cx-60,cy-60,0,0,0);
		wait(40);
		CreateEnemyFromScript("migo",cx+120,cy,0,0,0);
		wait(40);
		CreateEnemyFromScript("migo",cx-120,cy,0,0,0);
	}
	task subtask
	{
		wait(150);
		loop
		{
			SetShotColor(0,0,128);
			fire(GetX,GetY,60,3);
			SetShotColor(32,32,128);
			fire(GetX,GetY+12,30,3);
			SetShotColor(255,255,255);
			yield;
		}
	}
	task drawtask
	{
		let x=0;
		loop
		{	
			if(GetX>x+0.5)
			{
				flag=1;
			}
			else if(GetX<x-0.5)
			{
				flag=2;
			}
			else
			{
				flag=0;
			}
			if(alpha>0)
			{
				alpha-=2.5;
			}
			x=GetX;
			scroll++;
			yield;
		}
	}
	task fire(let x, let y, let delay,let a)
	{
		let obj = Obj_Create(OBJ_SHOT);
		Obj_SetPosition(obj, x, y);
		Obj_SetSpeed(obj, 0);
		Obj_SetAngle(obj, 0);
		ObjShot_SetGraphic(obj, 255);
		ObjShot_SetDelay(obj,delay);
		Obj_SetAutoDelete(obj,false);
		ObjShot_SetBombResist(obj,true);
		loop(delay)
		{
			Obj_SetX(obj,Obj_GetX(obj)-rand(-2,2));
			Obj_SetY(obj,Obj_GetY(obj)-a);
			yield;
		}
		Obj_Delete(obj);
	}
	function wait(w) 
	{
		loop(w)
		{
			yield;
		}
	}
}
script_enemy migo
{
	LoadUserShotData(GetCurrentScriptDirectory~"shot.txt");
	let angle=0;
	let cx=GetCenterX;
	let cy=GetCenterY;
	let time=30;
	let alpha=0;
	@Initialize
	{
		SetLife(70);
		SetDamageRateEx(10,0,100,0);
		SetInvincibility(60);
		SetTexture(GetCurrentScriptDirectory~"img\enemy\magic.png");
		shottask;
		movetask;
		bombtask;
	}
	@MainLoop
	{
		yield;
	}
	@Finalize
	{
	}
	@DrawLoop
	{
		SetGraphicAngle(0,0,angle);
		SetGraphicRect(0,0,72,72);
		DrawGraphic(GetX(),GetY());
		angle++;
		if(alpha<255)
		{
			alpha+=5;
		}
	}
	task shottask
	{
		wait(120);
		loop
		{
			let count=0;
			let shot=8/GetEnemyNum;
			loop(20)
			{
					loop(shot)
					{
						CreateShot01(GetX,GetY,rand(0.7,1.3),GetAngleToPlayer+rand(-count,count),135,20);
					}
					count+=5;
					wait(3);
			}
			wait(120);
		}
	}
	task movetask
	{
		wait(120);
		loop
		{
			wait(120);
			move(rand(40, 80), rand(-80, 80), 30,GetClipMinX + 32, GetClipMinY + 80,GetClipMaxX - 32, GetClipMinY + 160);
			wait(120);
		}
	}
	task bombtask
	{
		loop
		{
			if(OnBomb)
			{
				SetAlpha(64);
				SetDamageRateEx(0,0,0,0);
			}
			else
			{
				SetAlpha(alpha);
				SetDamageRateEx(10,0,100,0);
				SetCollisionA(GetX(),GetY(),24);
				SetCollisionB(GetX(),GetY(),24);
			}
			yield;
		}
	}
	function move(xMove, yAdd, frame, left, top, right, bottom)
	{
    		let x;
    		let y;
		if(GetPlayerX < GetX) 
		{
			x = GetX - xMove;
			if(x < left) 
			{
				x = GetX + xMove;
			}
		} 
		else {
			x = GetX + xMove;
			if(right < x)
			{
				x = GetX - xMove;
			}
		}
		y = GetY + yAdd;
		if(y < top)
		{
			y = top;
		}
		else if(bottom < y)
		{
			y = bottom;
		}
  			SetMovePosition02(x, y, frame);
	}
	function wait(w) 
	{
		loop(w)
		{
			yield;
		}
	}
}

script_enemy migo2
{
	LoadUserShotData(GetCurrentScriptDirectory~"shot.txt");
	let angle=0;
	let cx=GetCenterX;
	let cy=GetCenterY;
	let time=30;
	let alpha=0;
	@Initialize
	{
		SetLife(80);
		SetDamageRateEx(10,0,100,0);
		SetInvincibility(60);
		SetTexture(GetCurrentScriptDirectory~"img\enemy\magic.png");
		shottask;
		movetask;
		bombtask;
	}
	@MainLoop
	{
		yield;
	}
	@Finalize
	{
		DeleteEnemyShot(CHILD);
	}
	@DrawLoop
	{
		SetGraphicAngle(0,0,angle);
		SetColor(64,255,64);
		SetGraphicRect(0,0,72,72);
		DrawGraphic(GetX(),GetY());
		angle++;
		if(alpha<255)
		{
			alpha+=5;
		}
	}
	task shottask
	{
		wait(120);
		loop
		{
			let count=0;
			electoro(GetX,GetY,GetAngleToPlayer+rand(-30,30),0,0);
			wait(320);
		}
	}
	task movetask
	{
		wait(120);
		loop
		{
			wait(30);
			move(rand(40, 80), rand(-40, 40), 60,GetClipMinX + 32, GetClipMinY + 80,GetClipMaxX - 32, GetClipMinY + 160);
			wait(60);
		}
	}
	task bombtask
	{
		loop
		{
			if(OnBomb)
			{
				SetAlpha(64);
				SetDamageRateEx(0,0,0,0);
			}
			else
			{
				SetAlpha(alpha);
				SetDamageRateEx(10,0,100,0);
				SetCollisionA(GetX(),GetY(),24);
				SetCollisionB(GetX(),GetY(),24);
			}
			yield;
		}
	}
	task electoro(let x, let y, let angle,let angle2,let flag)
	{
		let length=rand(20,30);
		let width=0;
		let count=0;
		let obj = Obj_Create(OBJ_LASER);
		Obj_SetPosition(obj, x, y);
		Obj_SetAngle(obj, angle+angle2);
		ObjShot_SetGraphic(obj, 254);
		ObjShot_SetDelay(obj, 0);
		ObjLaser_SetLength(obj, length);
		ObjLaser_SetWidth(obj, 4);
		Obj_SetAutoDelete(obj,false);
		ObjLaser_SetSource(obj, false);
		Obj_SetCollisionToPlayer(obj,false);
		yield;
		if(Obj_GetY(obj)<GetClipMaxY+16&&Obj_GetY(obj)>GetClipMinY-16&&Obj_GetX(obj)<GetClipMaxX+16&&Obj_GetX(obj)>GetClipMinX-16)
		{
				if(GetEnemyShotCount<900||flag<10)
				{
					if(GetEnemyShotCount<600||flag<30)
					{
						electoro(Obj_GetX(obj)+(length-5)*cos(angle+angle2),Obj_GetY(obj)+(length-5)*sin(angle+angle2),GetAngleToPlayer+rand(-30,30),angle2,flag+1);
					}
					if(GetEnemyShotCount<600&&flag%10==5)
					{
						electoro(Obj_GetX(obj)+(length-5)*cos(angle+angle2),Obj_GetY(obj)+(length-5)*sin(angle+angle2),GetAngleToPlayer+rand(-30,30),rand(20,40),flag+1);
					}
					if(GetEnemyShotCount<600&&flag%10==0)
					{
						electoro(Obj_GetX(obj)+(length-5)*cos(angle+angle2),Obj_GetY(obj)+(length-5)*sin(angle+angle2),GetAngleToPlayer+rand(-30,30),rand(-20,-40),flag+1);
					}
					if(flag<=15)
					{
						electoro2(Obj_GetX(obj)+length*cos(angle+angle2),Obj_GetY(obj)+length*sin(angle+angle2),GetAngleToPlayer+rand(-30,30),rand(-30,30),flag+1);
					}
				}
		}
		wait(5);
		ObjLaser_SetWidth(obj, width);
		while(!Obj_BeDeleted(obj))
		{
			if(count==100)
			{
				Obj_Delete(obj);
			}
			if(count<60&&count>30)
			{
				width+=0.3;
				Obj_SetCollisionToPlayer(obj,false);
			}
			else if(count>70)
			{
				width-=0.3;
				Obj_SetCollisionToPlayer(obj,false);
			}
			else if(count<60)
			{
				Obj_SetCollisionToPlayer(obj,false);
			}
			else
			{
				Obj_SetCollisionToPlayer(obj,true);
			}
			ObjLaser_SetLength(obj, length);
			ObjLaser_SetWidth(obj, width);
			count++;
			yield;
		}
	}
	task electoro2(let x, let y, let angle,let angle2,let del)
	{
		let length=rand(0,30);
		let flag=rand_int(0,30);
		let width=0;
		let count=0;
		let obj = Obj_Create(OBJ_LASER);
		Obj_SetPosition(obj, x, y);
		Obj_SetAngle(obj, angle+angle2);
		ObjShot_SetGraphic(obj, 254);
		ObjShot_SetDelay(obj, 0);
		ObjLaser_SetLength(obj, length);
		ObjLaser_SetWidth(obj, 4);
		Obj_SetAutoDelete(obj,false);
		ObjLaser_SetSource(obj, false);
		Obj_SetCollisionToPlayer(obj,false);
		wait(6);
		ObjLaser_SetWidth(obj, width);
		while(!Obj_BeDeleted(obj))
		{
			if(count==100)
			{
				Obj_Delete(obj);
			}
			if(count<60&&count>30)
			{
				width+=0.2;
				Obj_SetCollisionToPlayer(obj,false);
			}
			else if(count>70)
			{
				width-=0.2;
				Obj_SetCollisionToPlayer(obj,false);
			}
			else if(count<60)
			{
				Obj_SetCollisionToPlayer(obj,false);
			}
			else
			{
				Obj_SetCollisionToPlayer(obj,true);
			}
			ObjLaser_SetLength(obj, length);
			ObjLaser_SetWidth(obj, width);
			count++;
			yield;
		}
	}
	function move(xMove, yAdd, frame, left, top, right, bottom)
	{
    		let x;
    		let y;
		if(GetPlayerX < GetX) 
		{
			x = GetX - xMove;
			if(x < left) 
			{
				x = GetX + xMove;
			}
		} 
		else {
			x = GetX + xMove;
			if(right < x)
			{
				x = GetX - xMove;
			}
		}
		y = GetY + yAdd;
		if(y < top)
		{
			y = top;
		}
		else if(bottom < y)
		{
			y = bottom;
		}
  			SetMovePosition02(x, y, frame);
	}
	function wait(w) 
	{
		loop(w)
		{
			yield;
		}
	}
}
